<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<script type="text/javascript">
    function getUrlParam(sUrl,sKey){
        var param=sUrl.split('#')[0].split('?')[1];
        var strs=param.split('&');
        var arrs=[];
        if(sKey){
            for(var i=0,len=strs.length;i<len;i++){
                var tmp=strs[i].split('=');
                if (tmp[0] == sKey)
                    arrs.push(tmp[1]);
            }
             if(arrs.length==1){
                return arrs[0];
             }else if(arrs.length==0){
                 return "";
             }else{
                 return arrs;
             }
        }else{
//           不指定参数名称，返回全部的参数对象或者{}
            var arrObj={};
            for(var i=0,len=strs.length;i<len;i++){
                var tmp=strs[i].split('=');
                if(tmp[0]!=""&& !(tmp[0] in arrObj)){
                    arrObj[tmp[0]]=tmp[1];
                }
            }
            return arrObj;

        }

    }

    console.log(getUrlParam('https://www.baidu.com/baidu?tn=monline_3_dg&ie=utf-8&wd=thymeleaf'));
</script>
</body>
</html>